package main

import (
	"fmt"
	"html/template"
	"net/http"
)

func helloWorld(w http.ResponseWriter, r *http.Request) {
	//创建模板的两种方式
	//t, err := template.ParseFiles("./http/hello.tpl")
	t, err := template.New("hello.tpl").ParseFiles("./http/hello.tpl")
	if err != nil {
		fmt.Printf("parse template failed %v \n", err)
		return
	}
	name := "zhangsan"
	t.Execute(w, name)
}

func main() {
	http.HandleFunc("/helloworld", helloWorld)
	error := http.ListenAndServe(":8090", nil)
	if error != nil {
		fmt.Println("http server failed %v \n", error)
	}
}
